import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
import local from '@/utils/local'
import { ElMessage } from 'element-plus'
import Layout from '../layout/index.vue'

const routes: Array<RouteRecordRaw> = [
  {
    path: '/',
    name: 'Layout',
    component: Layout,
    redirect: '/vueKnowledge',
    children: [
      {
        path: '/vueKnowledge',
        name: 'vueKnowledge',
        meta: { mark: 'public', title: "VUE知识", icon: 'vue' } /**请添加：confer: 私有的（涉及权限的），public：公有的（公告页面） */,
        component: () => import(/* webpackChunkName: "VueKnowledge" */ '@/views/vueKnowledge/index.vue'),
        children: [
          {
            path: '/vueKnowledge/konwledgeOne',
            name: 'konwledgeOne',
            meta: { mark: 'public', title: "VUE知识一", icon: 'bianjibiaoge' } /**请添加：confer: 私有的（涉及权限的），public：公有的（公告页面） */,
            component: () => import(/* webpackChunkName: "konwledgeOne" */ '@/views/vueKnowledge/components/konwledgeOne.vue')
          },
          {
            path: '/vueKnowledge/konwledgeTwo',
            name: 'konwledgeTwo',
            meta: { mark: 'public', title: "VUE知识二", icon: 'bianjibiaoge' } /**请添加：confer: 私有的（涉及权限的），public：公有的（公告页面） */,
            component: () => import(/* webpackChunkName: "konwledgeTwo" */ '@/views/vueKnowledge/components/konwledgeTwo.vue')
          },
          {
            path: '/vueKnowledge/konwledgeThree',
            name: 'konwledgeThree',
            meta: { mark: 'public', title: "VUE知识三", icon: 'bianjibiaoge' } /**请添加：confer: 私有的（涉及权限的），public：公有的（公告页面） */,
            component: () => import(/* webpackChunkName: "konwledgeThree" */ '@/views/vueKnowledge/components/konwledgeThree.vue')
          },
          {
            path: '/vueKnowledge/konwledgeFour',
            name: 'konwledgeFour',
            meta: { mark: 'public', title: "VUE知识四", icon: 'bianjibiaoge' } /**请添加：confer: 私有的（涉及权限的），public：公有的（公告页面） */,
            component: () => import(/* webpackChunkName: "konwledgeFour" */ '@/views/vueKnowledge/components/konwledgeFour.vue')
          },
          {
            path: '/vueKnowledge/konwledgeFive',
            name: 'konwledgeFive',
            meta: { mark: 'public', title: "VUE知识五", icon: 'bianjibiaoge' } /**请添加：confer: 私有的（涉及权限的），public：公有的（公告页面） */,
            component: () => import(/* webpackChunkName: "konwledgeFive" */ '@/views/vueKnowledge/components/konwledgeFive.vue')
          },
        ],
      },
      {
        path: '/jsKnowledge',
        name: 'jsKnowledge',
        meta: { mark: 'public', title: "JS知识", icon: 'js' } /**请添加：confer: 私有的（涉及权限的），public：公有的（公告页面） */,
        component: () => import(/* webpackChunkName: "JsKnowledge" */ '@/views/jsKnowledge/index.vue'),
        children: [

        ],
      },
      {
        path: '/cssKnowledge',
        name: 'cssKnowledge',
        meta: { mark: 'public', title: "CSS知识", icon: 'CSS' } /**请添加：confer: 私有的（涉及权限的），public：公有的（公告页面） */,
        component: () => import(/* webpackChunkName: "CssKnowledge" */ '@/views/cssKnowledge/index.vue'),
        children: [
          {
            path: '/cssKnowledge/cssPlugTailwind',
            name: 'cssPlugTailwind',
            meta: { mark: 'public', title: "Tailwind CSS", icon: 'bianjibiaoge' } /**请添加：confer: 私有的（涉及权限的），public：公有的（公告页面） */,
            component: () => import(/* webpackChunkName: "konwledgeOne" */ '@/views/cssKnowledge/components/cssPlugTailwind.vue')
          },
          {
            path: '/cssKnowledge/cssSportsAcrobatics',
            name: 'cssSportsAcrobatics',
            meta: { mark: 'public', title: "CSS技巧", icon: 'bianjibiaoge' } /**请添加：confer: 私有的（涉及权限的），public：公有的（公告页面） */,
            component: () => import(/* webpackChunkName: "konwledgeOne" */ '@/views/cssKnowledge/components/cssSportsAcrobatics.vue')
          },
        ],
      },
      {
        path: '/vuePlugInKnowledge',
        name: 'vuePlugInKnowledge',
        meta: { mark: 'public', title: "VUE插件知识", icon: 'jiantou' } /**请添加：confer: 私有的（涉及权限的），public：公有的（公告页面） */,
        component: () => import(/* webpackChunkName: "VuePlugInKnowledge" */ '@/views/vuePlugInKnowledge/index.vue'),
        children: [
          {
            path: '/vuePlugInKnowledge/richText',
            name: 'richText',
            meta: { mark: 'public', title: "富文本插件", icon: 'bianjibiaoge' } /**请添加：confer: 私有的（涉及权限的），public：公有的（公告页面） */,
            component: () => import(/* webpackChunkName: "konwledgeOne" */ '@/views/vuePlugInKnowledge/components/richText.vue')
          },
          {
            path: '/vuePlugInKnowledge/pdfViwe',
            name: 'pdfViwe',
            meta: { mark: 'public', title: "PDF预览插件", icon: 'bianjibiaoge' } /**请添加：confer: 私有的（涉及权限的），public：公有的（公告页面） */,
            component: () => import(/* webpackChunkName: "konwledgeOne" */ '@/views/vuePlugInKnowledge/components/pdfViwe.vue')
          },
          {
            path: '/vuePlugInKnowledge/wpsViwe',
            name: 'WPSViwe',
            meta: { mark: 'public', title: "WPS插件", icon: 'bianjibiaoge' } /**请添加：confer: 私有的（涉及权限的），public：公有的（公告页面） */,
            component: () => import(/* webpackChunkName: "konwledgeOne" */ '@/views/vuePlugInKnowledge/components/wpsViwe.vue')
          },
        ],
      },
      {
        path: '/vueComponentKnowledge',
        name: 'vueComponentKnowledge',
        meta: { mark: 'public', title: "VUE组件知识", icon: 'Vue-icon' } /**请添加：confer: 私有的（涉及权限的），public：公有的（公告页面） */,
        component: () => import(/* webpackChunkName: "VueComponentKnowledge" */ '@/views/vueComponentKnowledge/index.vue'),
        children: [
          {
            path: '/vueComponentKnowledge/tableConsent',
            name: 'tableConsent',
            meta: { mark: 'public', title: "表格封装", icon: 'bianjibiaoge' } /**请添加：confer: 私有的（涉及权限的），public：公有的（公告页面） */,
            component: () => import(/* webpackChunkName: "konwledgeOne" */ '@/views/vueComponentKnowledge/components/tableConsent.vue')
          },
        ],
      },
      {
        path: '/javaKnowledge',
        name: 'javaKnowledge',
        meta: { mark: 'public', title: "JAVA知识", icon: 'java' } /**请添加：confer: 私有的（涉及权限的），public：公有的（公告页面） */,
        component: () => import(/* webpackChunkName: "JavaKnowledge" */ '@/views/javaKnowledge/index.vue'),
        children: [

        ],
      },
      {
        path: '/otherKnowledge',
        name: 'otherKnowledge',
        meta: { mark: 'public', title: "其他知识", icon: 'qita' } /**请添加：confer: 私有的（涉及权限的），public：公有的（公告页面） */,
        component: () => import(/* webpackChunkName: "OtherKnowledge" */ '@/views/otherKnowledge/index.vue'),
        children: [
          {
            path: '/otherKnowledge/vsCodeSportsAcrobatics',
            name: 'vsCodeSportsAcrobatics',
            meta: { mark: 'public', title: "vscode技巧", icon: 'bianjibiaoge' } /**请添加：confer: 私有的（涉及权限的），public：公有的（公告页面） */,
            component: () => import(/* webpackChunkName: "konwledgeOne" */ '@/views/otherKnowledge/components/vsCodeSportsAcrobatics.vue')
          },
        ],
      },
    ]
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import(/* webpackChunkName: "Login" */ '../views/login/LoginView.vue')
  },
  {
    path: '/register',
    name: 'Register',
    component: () => import(/* webpackChunkName: "Login" */ '../views/login/RegisterView.vue')
  },
]

const router = createRouter({
  history: createWebHashHistory(),
  routes
})
// 前置守卫
router.beforeEach(async (to: any, from: any, next: any) => {
  const tokenObj = local.get('tokenObj')
  NProgress.start()
  document.title = to.meta.title ? `管理系统|${to.meta.title}` : '管理系统'
  if (!tokenObj && to.path === '/login') {
    next()
    NProgress.done()
    return
  } else if (!tokenObj && (to.path == '/register')) {
    next()
    NProgress.done()
    return
  } else if (!tokenObj && (to.path !== '/login') && (to.path !== '/register')) {
    next('/login')
    NProgress.done()
    return
  } else {
    next()
    NProgress.done()
    return
  }
})
// 后置守卫
router.afterEach((to: any, from: any) => {

})
export default router
